package com.gxa.controller;


import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.domain.dto.CourseSaveDTO;
import com.gxa.domain.dto.CourseUpdateDTO;
import com.gxa.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    // 查询所有健身课程-带分页
    @RequestMapping(value = "/findCourseAll",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findCourseAll(Integer page, Integer limit){
        return courseService.findCourseAll(page,limit);
    }


    // 查询
    @RequestMapping(value = "/findCourseByCourseId",method = RequestMethod.GET)
    @ResponseBody
    public Result findCourseByCourseId(Integer courseId){
        return courseService.findCourseByCourseId(courseId);
    }

    // 添加
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
//    public Result save(CourseSaveDTO courseSaveDTO){//普通对象方式接收参数：默认Params
    public Result save(@RequestBody CourseSaveDTO courseSaveDTO){//接收是json格式的对象
        return courseService.addCourse(courseSaveDTO);
    }

    // 修改
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@RequestBody CourseUpdateDTO courseUpdateDTO){
        return courseService.updateCourse(courseUpdateDTO);
    }

    // 删除
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(Integer courseId){
        return courseService.delCourseByCourseId(courseId);
    }

    // 搜索
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson search(String coursename,Integer page,Integer limit){
        return courseService.search(coursename,page,limit);
    }

}
